<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/6/2
 * Time: 11:40
 */

namespace Home\Controller;


class FreeController extends HomeController
{
    public $category_id = 147;
    public function index(){
        $this->meta($this->category_id);
        $cate_list = $this->category->getTree($this->category_id);
        $this->assign("cate_list",$cate_list);
        $this->display();
    }
    public function detail(){
        $this->meta($this->category_id);
        $cate_id = I("get.cate_id",0,"int");
        $community_detail =session("community_detail");
        if(IS_POST){
            $data=[
                'cate_id'=>I("post.cate_id",0,"int"),
                'name' =>I("post.name","","addslashes"),
                'tel'  =>I("post.tel","","addslashes"),
                'content'  =>I("post.content","","addslashes"),
                'create_time'=>time(),
                'community_id'=>$community_detail['id'],
            ];
            if($data['name']!=""){
                $contact =M("contact");
                if($contact->add($data)){
                    echo "<script>alert('提交成功');window.location.href='".U('Free/detail',array('cate_id'=>$cate_id))."';</script>";
                }
            }
        }
        $this->assign("cate_id",$cate_id);
        $document = M("document");
        $map =[
            'ot_document_article.community_ids'=>array("like",'%'.$community_detail['id'].'%'),
            'ot_document.status' =>1,
            'ot_document.pid' => 0,
            'ot_document.category_id' =>$cate_id
        ];
        $lists = $document->join("ot_document_article on ot_document.id =ot_document_article.id")->field("ot_document.id,ot_document.title,ot_document.create_time,ot_document_article.content")->where($map)->order("level desc,id desc")->select();
        $this->assign("lists",$lists);
        $this->display();
    }
    public function article_detail(){
        $this->meta($this->category_id);
        $id =I("get.id",0,"int");
        $data=$this->document->detail($id);
        $this->assign("data",$data);
        $this->display("Article/news_detail");
    }
}